package com.kbt.util.utils;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

/**
 * Created by shellex on 2015/10/13.
 */
public class SetingImage extends Activity{


    //根据手机屏幕的宽度高度手动计算设置图片的高度和宽度
    public static void setImageHeightWidth(int screenWidth,String url,ImageView view){
        ViewGroup.LayoutParams lp = view.getLayoutParams();
        lp.width = screenWidth;

        String[] url_params = url.split("&");
        int imageWidth = 0;
        int imageHeight = 0;
        if(url_params.length == 3){
            imageWidth = Integer.parseInt(url_params[1].split("=")[1]);
            imageHeight = Integer.parseInt(url_params[2].split("=")[1]);
        }

        if(imageWidth>0 && imageHeight>0){
            lp.height = new Float(imageHeight*screenWidth/imageWidth).intValue();
        }else{
            lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
        }
        view.setLayoutParams(lp);
        view.setMaxWidth(screenWidth);
        view.setMaxHeight(screenWidth * 10);
    }
    //即将开抢以及已抢完图片处理，高度==宽度
    public static void setImageHeightWidthTwo(int screenWidth,String url,ImageView view){
        ViewGroup.LayoutParams lp = view.getLayoutParams();
        lp.width = screenWidth;

        String[] url_params = url.split("&");
        int imageWidth = 0;
        int imageHeight = 0;
        if(url_params.length == 3){
            imageWidth = Integer.parseInt(url_params[1].split("=")[1]);
            imageHeight = Integer.parseInt(url_params[2].split("=")[1]);
        }

        if(imageWidth>0 && imageHeight>0){
            lp.height = lp.width;
        }else{
            lp.height = lp.width;
        }
        view.setLayoutParams(lp);
        view.setMaxWidth(screenWidth);
        view.setMaxHeight(screenWidth * 10);
    }
}
